<#include "./template/general_temp.ftl">

<#macro content>
<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-question"></i>问答管理</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content">
                <table id="question_dg">
                </table>
            </div>
        </div>
    </div>
    <!--/span-->

</div><!--/row-->
</#macro>

<#macro script>
<script type="text/javascript">
    function queryData(){
        //构造列表
        jQuery('#question_dg').datagrid({
            url:'${base}/system/question/list',
            fitColumns : true,
            striped : true,
            pagination : true,
            rownumbers : true,
            pageSize : 20,
            pageNumber : 1,
            pageList : [ 20, 50],
            loadMsg : '数据正在加载中...',
            singleSelect:true,
            queryParams : {},
            selectOnCheck : false,
            checkOnSelect : false,
            width:$('.box-content').width() * 0.985,
            columns : [[
                {field : 'title', title : '标题',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'creatorStr', title : '提问者',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.1, align: 'center'},
                {field : 'createTimeStr', title : '提问时间',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'status', title : '状态',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'updater', title : '最后操作人',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'ctrl', title : '操作',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center',
                    formatter:function(value,row,index){

                        var up;
                        if(row.isUp == 1){
                            up = "<label class='checkbox-inline'><input type='checkbox' value='1' checked='checked' onchange='checkIn(this," + row.id + ")'> 推荐</label>";
                        }else{
                            up = "<label class='checkbox-inline'><input type='checkbox' value='1' onchange='checkIn(this," + row.id + ")'> 推荐</label>";
                        }

                        var editBtn = "<a class='btn btn-info' href='javascript:void(0)' onclick='edit(" + row.id +")'><i class='glyphicon glyphicon-edit icon-white'></i>编辑</a>";

                        return up + editBtn;
                    }
                }
            ]],
            onLoadSuccess:function(data){
            },
            onClickRow: function (rowIndex, rowData) {

            }
        });
    }

    function checkIn(obj,id){
        console.info(obj);
        var isUp = 1;
        if($(obj).attr("checked") == "checked"){
            console.info("之前是选择的");
            isUp = 0;
        }else{
            console.info("之前是不选择的");
            isUp = 1;
        }
        if(window.confirm("是否变更？")){
            jQuery.ajax({
                type: "POST",
                url: '${base}/system/question/up',
                dataType:"json",
                data: {"id": id,"isUp":isUp},
                success: function(data){
                    if(data.status == 1) {
                        alert("变更成功！");
                        queryData();
                    }else{
                        alert("变更失败！");
                    }
                },
                error: function (obj){
                    console.info(obj);
                }
            });
        }
    }

    $(document).ready(function () {
        queryData();
    });

    function edit(id){
        window.location = "${base}/system/question/edit?id=" + id;
    }
</script>
</#macro>
